let arr = [1, 6, 4, 8, 3, 5, 1, 11]
// 思路选出一个最大的放到最后面

const changePosition = (arr, i, j) => {
    let temp
    temp = arr[i]
    arr[i] = arr[j]
    arr[j] = temp
}

const compare = (num1, num2) => {
    if (num1 > num2) {
        return true
    } else {
        return false
    }
}

const selectSort = () => {
    for (let i = 0; i < arr.length; i++) {
        let maxIndex = 0;
        for (let j = 0; j < arr.length - i; j++) {
            if (!compare(arr[maxIndex], arr[j])) {
                maxIndex = j;
            }
        }
        changePosition(arr, maxIndex, arr.length - i - 1);
    }
}
selectSort();
console.log(arr);